const Controller = require("uni-cloud-router").Controller;
const {validateToken} = require('validdate-token');
module.exports = class UserController extends Controller{
	/**
	 * @param {Object} token
	 * 验证token
	 */
	async _checkToken(token){
		let tokenRes;
		try{
			tokenRes = await validateToken(token);
			if(tokenRes.code !== 0){
				return{
					status:-1,
					msg:"稍后重试",
					errCode:tokenRes.errCode
				}
			} else {
				return {
					status:0,
					msg:"token有效",
				}
			}
		}catch(e){
			return {
			  status: -1,
			  errCode: 'TOKEN_INVALID',
			  msg: 'token无效'
			}
		}
	}
	/**
	 * 获取钻机信息
	 * 2020-08-09
	 */
	async getDrillInfo(){
		return this.service.drillAdmin.getDrillInfo();
	}
	/**
	 * 2020-09-19
	 * 删除项目里面的钻机
	 * ----（分配钻机时钻机已在其他项目里面但是任然选择分配）
	 */
	async deleteDrillInProject(){
		let {drillID} = this.ctx.data;
		return this.service.drillAdmin.deleteDrillInProject({drillID});
	}
	/**
	 * 2020-09-15
	 * 添加至项目的时候，修改钻机状态
	 */
	async updateDrillStatus(){
		let { curDrillStatus,drillID } = this.ctx.data;
		return this.service.drillAdmin.updateDrillStatus({ curDrillStatus,drillID });
	}
	/**
	 * 2020-09-12
	 * 给项目分配钻机
	 */
	async allotDrillInProject() {
		let {
			projectID,
			drillID
		} = this.ctx.data;
		return this.service.drillAdmin.allotDrillInProject({
			projectID,
			drillID
		});
	}
	/**
	 * 2020-6-12
	 * 员工绑定钻机
	 */
	async drillBindWorker(){
		let { wkID,drillID } = this.ctx.data;
		return this.service.drillAdmin.drillBindWorker(wkID,drillID);
	}
}